/*

    This file is part of Blue Violin.

    Blue Violin is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Blue Violin is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero Public License for more details.

    You should have received a copy of the GNU Affero Public License
    along with Blue Violin.  If not, see <http://www.gnu.org/licenses/>.

    Blue Violin  Copyright (C) 2008  Blue Violin, Inc. & Josh Watts <josh.watts@blueviolin.org>
	For more information, visit http://www.blueviolin.org/

    This program comes with ABSOLUTELY NO WARRANTY.

*/

function OpenFile()
{
	this.m_oPrevious = null;
}


OpenFile.prototype.select = function()
{
	var oElement = window.event.srcElement;
	var txtFileName = $get("txtFileName");

	if ("IMG" == oElement.tagName.toUpperCase())
	{
		oElement = oElement.parentNode;
	}


	if (null != this.m_oPrevious)
	{
		this.m_oPrevious.style.backgroundColor = "white";
		this.m_oPrevious.style.color = "black";
	}

	oElement.style.backgroundColor = "#01457A";
	oElement.style.color = "white";

	txtFileName.value = oElement.childNodes.item(1).data.trim();

	this.m_oPrevious = oElement;
};


OpenFile.prototype.open = function()
{
	if (null != this.m_oPrevious)
	{
		window.dialogArguments.name = this.m_oPrevious.childNodes.item(1).data.trim();
	}
	window.close();
};


OpenFile.prototype.selectAndOpen = function()
{
	var oElement = window.event.srcElement;
	var sFileName = "";

	if ("IMG" == oElement.tagName.toUpperCase())
	{
		oElement = oElement.parentNode;
	}
	sFileName = oElement.childNodes.item(1).data.trim();
	window.dialogArguments.name = sFileName;
	window.close();
}


OpenFile.prototype.cancel = function()
{
	window.dialogArguments.name = null;
	window.close();
};


OpenFile.prototype.keyPress = function()
{
	var oEvent = window.event;
	if (27 == oEvent.keyCode)
	{
		// ESC key
		window.dialogArguments.name = null;
		window.close();
	}
	
};

var oOpenFile = new OpenFile();
